package com.appcenter.application.controller;

import com.appcenter.application.input.Job.*;
import com.appcenter.application.service.JobService;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzappcenter/job")
@Api("岗位管理相关API")
public class JobController {
    @Autowired
    JobService jobService;

    @ApiOperation(value = "加载岗位", notes = "加载岗位", produces = "application/json")
    @PostMapping("/pageLoad")
    public ResponseEntity<JsonResult> PageLoad(@RequestBody PageLoadInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobService.PageLoad(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "加载岗位", notes = "加载岗位", produces = "application/json")
    @PostMapping("/getjobs")
    public ResponseEntity<JsonResult> GetJobs(@RequestBody GetJobsInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobService.GetJobs(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "创建岗位", notes = "创建岗位", produces = "application/json")
    @PostMapping("/createjob")
    public ResponseEntity<JsonResult> createjob(@RequestBody CreateJobInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobService.CreateJob(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "编辑岗位", notes = "编辑岗位", produces = "application/json")
    @PostMapping("/editjob")
    public ResponseEntity<JsonResult> editJob(@RequestBody EditJobInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobService.EditJob(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "删除岗位", notes = "删除岗位", produces = "application/json")
    @PostMapping("/deletejob")
    public ResponseEntity<JsonResult> deleteJob(@RequestBody DeleteJobInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobService.DeleteJob(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "编辑状态", notes = "编辑状态", produces = "application/json")
    @PostMapping("/editjobstatus")
    public ResponseEntity<JsonResult> editJobStatus(@RequestBody EditJobInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobService.EditJobStatus(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
